package top.someapp.dxf2dsvg.cad;

import com.aspose.cad.fileformats.cad.cadconsts.CadEntityTypeName;
import com.aspose.cad.fileformats.cad.cadobjects.CadBaseEntity;

import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zwz
 * Created on 2020-04-22
 */
public class Entities {
    private Entities() {
        // prevent outer new instance
    }

    private static final Map<Integer, String> entityTypeMap = new HashMap<>();

    public static String typeNameOf(@Nonnull CadBaseEntity entity) {
        if (entityTypeMap.isEmpty()) {
            Collection<String> names = CadEntityTypeName.getNames(CadEntityTypeName.class);
            for (String name : names) {
                long value = CadEntityTypeName.getValue(CadEntityTypeName.class, name);
                entityTypeMap.put((int) value, name);
            }
        }
        return entityTypeMap.get(entity.getTypeName());
    }
}
